package org.rvk.vms.service.user;

import org.rvk.vms.dal.entities.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Represents the common user of athena product.
 * 
 * @author Ashish Kumar Sinha <aksinha.mail@gmail.com>
 * 
 */
public class VmsUser implements UserDetails {
	private static final long serialVersionUID = -1103507048073400268L;
	
	User user;
	
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		List<GrantedAuthorityImpl> list = new ArrayList<GrantedAuthorityImpl>();
		GrantedAuthorityImpl authorityImpl = new GrantedAuthorityImpl("ROLE_USER");
		list.add(authorityImpl);
		return list;
	}

	@Override
	public String getPassword() {
		return user.getPassword();
	}

	@Override
	public String getUsername() {
		return user.getUsername();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}



	class GrantedAuthorityImpl implements GrantedAuthority {
		String role;

		public GrantedAuthorityImpl(String role) {
			this.role = role;
		}

		@Override
		public String getAuthority() {
			return role;
		}

	}
}
